import Content from '@/sheep/layouts/content.vue';
import { request } from '@/sheep/request';
import { SELECT, CRUD } from '@/sheep/request/crud';

const route = {
  path: 'data',
  name: 'shop.admin.data',
  component: Content,
  meta: {
    title: '数据维护',
  },
  children: [
    {
      path: 'page',
      name: 'shop.admin.data.page',
      component: () => import('./page/index.vue'),
      meta: {
        title: '页面链接',
      },
    },
    {
      path: 'richtext',
      name: 'shop.admin.data.richtext',
      component: () => import('./richtext/index.vue'),
      meta: {
        title: '富文本',
      },
    },
    {
      path: 'area',
      name: 'shop.admin.data.area',
      component: () => import('./area/index.vue'),
      meta: {
        title: '省市区',
      },
    },
    {
      path: 'faq',
      name: 'shop.admin.data.faq',
      component: () => import('./faq/index.vue'),
      meta: {
        title: '常见问题',
      },
    },
    {
      path: 'express',
      name: 'shop.admin.data.express',
      component: () => import('./express/index.vue'),
      meta: {
        title: '快递公司',
      },
    },
    {
      path: 'fakeuser',
      name: 'shop.admin.data.fakeuser',
      component: () => import('./fakeUser/index.vue'),
      meta: {
        title: '虚拟用户',
      },
    },
  ],
};

const api = {
  page: {
    ...CRUD('shop/admin/data/page'),
    select: (params) => SELECT('shop/admin/data/page', params),
  },
  area: {
    ...CRUD('shop/admin/data/area'),
    select: (params) => SELECT('shop/admin/data/area', params),
  },
  faq: {
    ...CRUD('shop/admin/data/faq'),
  },
  richtext: {
    ...CRUD('shop/admin/data/richtext'),
    select: (params, type = 'page') =>
      request({
        url: `shop/admin/data/richtext/select?type=${type}`,
        method: 'GET',
        params,
      }),
  },
  express: {
    ...CRUD('shop/admin/data/express'),
    select: (params) => SELECT('shop/admin/data/express', params),
  },
  fakeUser: {
    ...CRUD('shop/admin/data/fakeUser'),
    select: (params) => SELECT('shop/admin/data/fakeUser', params),
    random: (data) =>
      request({
        url: 'shop/admin/data/fakeUser/random',
        method: 'POST',
        data,
        timeout: 60000,
      }),
    getRandom: () =>
      request({
        url: 'shop/admin/data/fakeUser/getRandom',
        method: 'GET',
      }),
  },
};

export { route, api };
